<template>
    <div class="PopupAdd">
        <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="visible" title=""
            :show-close="false" align-center class="dialogAdd">
            <div class="dialog_content">
                <div class="dialog_header">
                    <div class="title">
                        <img src="@/assets/images/rectangle07.png" alt="">
                        <span>新增</span>
                    </div>
                </div>
                <div class="dialog_body">
                    <div class="left">
                        <div>
                            <div>
                                <el-input v-model="addmentName" placeholder="输入姓名查询" :prefix-icon="Search" />
                            </div>

                        </div>
                        <div class="platform_tree">
                            <el-scrollbar height="236px" always>
                                <el-tree ref="treeRef" :default-expanded-keys="expanded_keys" :props="defaultProps"
                                    node-key="id" :data="platformData.list" show-checkbox
                                    @check-change="handleCheckChange" :filter-node-method="filterNode" />
                            </el-scrollbar>
                        </div>
                    </div>
                    <div class="right">
                        <el-form class="form" ref="ruleFormRef" label-width="110px" :model="platformData.formParams">
                            <el-form-item label="角色">
                                <el-radio-group v-model="platformData.formParams.remarks" class="ml-4">
                                    <el-radio :label="1">签发人</el-radio>
                                    <el-radio :label="2">负责人</el-radio>
                                    <el-radio :label="3">许可人</el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="状态">
                                <el-radio-group v-model="platformData.formParams.remarks" class="ml-4">
                                    <el-radio :label="1">启用</el-radio>
                                    <el-radio :label="2">禁用</el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="备注">
                                <el-input v-model="platformData.formParams.remarks"
                                    :autosize="{ minRows: 4, maxRows: 6 }" type="textarea"
                                    show-word-limit resize="none" />
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
                <div class="btn">
                    <el-button type="warning" @click="handleConfirm()">发 送</el-button>
                    <el-button @click="handleClose">取 消</el-button>
                </div>
            </div>
        </el-dialog>
    </div>

</template>

<script lang="ts" setup>
import { ElTree } from 'element-plus'
import { Search } from '@element-plus/icons-vue'
const props = defineProps({
    dialogVisible: {
        type: Boolean,
        default: false
    },
})

let visible = ref(false);
let addmentName = ref('');//项目名称

//emit(父组件中的自定义方法)
const emit = defineEmits(['closeDialog', 'confirmDialog', 'updateList']);

watch(() => props.dialogVisible, async (newValue, oldValue) => {
    visible.value = newValue;
    if (newValue && platformData.list.length == 0) {
        getPlatformProject();
    }

});

//监听项目名称
watch(() => addmentName.value, (newValue) => {
    treeRef.value!.filter(newValue);//搜索发送对象
})


const platformData = reactive({
    list: [],
    formParams: {
        remarks: 1,
    }
})

interface InoticeUserList {
    dptId: string;
    dptName: string;
}


const ruleFormData = reactive({
    title: '',//标题
    content: '',//内容
    noticeUserList: [] as Array<InoticeUserList>,
    sendType: 1,//发送类型：1-立即发送，2-定时发送
    createTime: '',//定时发送时间
})

const expanded_keys: any = ref([]);//默认展开项

const defaultProps = {
    children: 'children',
    label: 'name',
}

interface Tree {
    label: string
    children?: Tree[]
}
const treeRef = ref<InstanceType<typeof ElTree>>()

//勾选平台改变时
const handleCheckChange = (data: Tree) => {
    
}

const filterNode = (value: any, data: any) => {
    if (!value) return true
    console.log('data', data);

    return data.name.includes(value)
}
//获取平台部门列表
const getPlatformProject = () => {
   
}

//点击确定按钮
const handleConfirm = () => {

}
//关闭弹窗
const handleClose = () => {
    emit("closeDialog");
}

</script>

<style scoped lang="scss">
.PopupAdd {
    :deep(.dialogAdd) {
        width: 780px;
        min-height: 550px;
        border: 1px solid rgba(192, 164, 91, 1);
        background: rgba(255, 255, 255, 1);
        border-radius: 2px;

        .el-dialog__header {
            padding: 0;

        }

        .el-dialog__body {
            padding: 0;

            .dialog_content {
                .dialog_header {
                    padding: 0;
                    height: 59px;
                    padding: 8px 32px 4px 62px;
                    line-height: 52px;
                    font-size: 16px;
                    font-weight: 400;
                    color: rgba(0, 0, 0, 1);
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    border-bottom: 1px dashed rgb(112, 105, 95);

                    // border-bottom: 2px dotted rgba(192, 164, 91, 1);
                    .title {
                        display: flex;
                        align-items: center;

                        img {
                            width: 4px;
                            height: 22px;
                            margin-right: 15px;
                        }

                    }

                    .close {
                        width: 25px;
                        height: 25px;
                        cursor: pointer;

                    }
                }

                .dialog_body {
                    display: flex;
                    padding: 28px 46px 0 46px;

                    .left {
                        width: 280px;

                        .right_text {
                            font-size: 16px;
                            font-weight: 400;
                            letter-spacing: 0px;
                            line-height: 19px;
                            color: rgba(0, 0, 0, 1);
                            margin-bottom: 20px;
                            margin-top: 8px;

                            .required {
                                color: red;
                                vertical-align: middle;
                            }
                        }

                        .el-input {
                            width: 260px;
                            margin-top: 10px;

                            .el-input__wrapper {
                                border-radius: 2px;
                                border: 1px solid rgba(0, 0, 0, 0.15);
                                box-shadow: none;

                                &.is-focus {
                                    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(192, 164, 91, 0.8);
                                    border-color: rgba(192, 164, 91, 0.8);
                                }
                            }

                            .el-input-group__append {
                                width: 28px;
                                padding: 0;
                                border-radius: 0;
                                background-color: rgba(192, 164, 91, 0.3);
                                // background-color: #fff;
                                cursor: pointer;
                                box-shadow: none;
                                border: 0.5px solid rgba(192, 164, 91, 0.5);
                                border-left: 0;
                                display: flex;
                                justify-content: center;
                                align-items: center;
                            }
                        }

                        .platform_tree {
                            margin-top: 23px;
                            width: 270px;
                            height: 236px;
                            // background: rgba(112, 105, 95, 0.1);
                            padding: 0px 10px 0px 0px;

                            .el-tree {
                                background-color: transparent;
                                font-size: 14px;

                                .el-tree-node__content {
                                    height: 30px;
                                    line-height: 30px;

                                    &:hover {
                                        background-color: transparent;
                                    }

                                    .el-icon {
                                        font-size: 14px;
                                        color: rgba(192, 164, 91, 1);

                                        &.is-leaf {
                                            color: transparent;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    .right {
                        flex: 1;
                        padding-top: 20px;

                        .el-form {
                            flex-wrap: wrap;

                            .el-form-item {
                                margin-bottom: 22px;
                                width: 395px;

                                &:nth-child(2n+1) {
                                    margin-right: 20px;
                                }

                                .el-form-item__label {
                                    width: 135px;
                                }

                                .el-radio-group {
                                    .el-radio {
                                        &:first-child {
                                            width: 100px;
                                        }

                                        &:nth-child(2) {
                                            width: 100px;
                                        }
                                    }
                                }

                                &.detailsDes {
                                    width: 100%;
                                    margin-right: 0;
                                    position: relative;

                                    .photoText {
                                        position: absolute;
                                        left: -78px;
                                        top: 30px;
                                    }
                                }
                            }
                        }
                    }
                }


                .btn {
                    margin-top: 20px;
                    text-align: right;
                    padding-right: 80px;

                    .el-button--info {
                        margin-left: 10px;
                    }
                }
            }
        }



    }
}

.el-tree {
    :deep(.el-icon) {
        svg {
            width: 12px;
            height: 12px;
            background: url("@/assets/images/images_new/arrow-down.png");
            background-size: 100% 100%;
        }
    }
}
</style>